
//index.js
//获取应用实例
var imageUtil = require('../../utils/util.js');

var usercity;
var city;
var tp;

var app = getApp();
var https = "https://www.moreclub.cn/";
var htp = 'http://more-image.oss-cn-beijing.aliyuncs.com/pinzuominiapp/';
var http = 'http://10.150.7.245:8006/';
var http1 = 'http://10.150.7.248:8001/'
var http2 = 'http://59.110.53.149:8088/'
var uid;
let col1H = 0;
let col2H = 0;
let fabuH = 0;
var images = []
var isinto;
var showbox;
var kaiguan=null;
var pages;
var page = -1;
var mid;
var showPerson=false;

var getList = function (that){

  var access_token = wx.getStorageSync('inToken');
  //var mid = wx.getStorageSync('mid');
  //发布内容

  wx.request({

    // url: https + 'v2/signinter/open/merchantInters?mid='+mid+'&pn=0&access_token=' + access_token,
    url: https + 'v2/signinter/open/merchantInters?mid='+mid + '&pn=0',
    success: function (res) {
      console.log(res)
      var resData = res.data.data;

      var dataArr = [];//创建一个新数组
      var newarr = [];
      for (var key in resData) {
        //console.log(resData[key])
        var content = resData[key].content;
        var gift = resData[key].gift;
        var type1 = resData[key].type;
        var uid2 = resData[key].uid;
        var exprise1 = resData[key].exprise;
        var merchantName = resData[key].merchantName;
        var timestamp = resData[key].timestamp;
        var nickName = resData[key].nickName;
        var userThumb = resData[key].userThumb;
        var colseTime = resData[key].colseTime;
        var sid = resData[key].sid;

        if (type1 == 5) {
          var txt = 0;
        }
        if (type1 == 3) {
          var txt = 1;
        }
        if (type1 == 6) {
          var txt = 2;
        }
        if (type1 == 4) {
          var txt = 3;
        }
        if (type1 == 1) {
          var txt = 4;
        }
        if (type1 == 2) {
          var txt = 5;
        }

        var obj = {};
        obj.exprise1 = exprise1
        obj.userThumb = userThumb
        obj.nickName = nickName
        obj.timestamp = timestamp
        obj.merchantName = merchantName
        obj.gift = gift
        obj.txt = txt
        obj.uid2 = uid2
        obj.content = content
        obj.sid = sid
        obj.colseTime = colseTime
        dataArr.push(obj);
        newarr.push(exprise1)
      }
      try {
        wx.setStorageSync('dataArr', dataArr);
        wx.setStorageSync('resData', resData);
      } catch (e) {
      }
      that.setData({
        dataArr: dataArr,
        uid: uid
      })
    }
  })
}

var personList = function (that,mid){
  
  //签到人数显示
  wx.request({
    url: https + 'v1/signin/open/merchants/morespace/' + mid ,
    data: {
      pn: page,
      ps: 8
    },
    //dataType: "application/json",
    success: function (res) {
      console.log(res)
      if (res.data.success) {
        var judata = res.data.data
       
        var o = {}
        if (judata.preCount) {
          o.preCount = judata.preCount
        }
        if (judata.sininCount){
          o.sininCount = judata.sininCount 
        }
        
        that.setData({
          o:o
        })
        if (judata != null) {
          var datalist = res.data.data.sininMoreSpaces;
        
          let personArr = []

          for (var i = 0; i < datalist.length; i++) {

            var p = datalist[i].userAvatar;
            var name = datalist[i].userName;
            // var day = datalist[i].day;
            var age = datalist[i].age;
            var gender = datalist[i].gender;
            var merchantName = datalist[i].merchantName;
            var mid = datalist[i].mid;
            var uid1 = datalist[i].uid;
            var exprise = datalist[i].exprise
            var signinTime = datalist[i].signinTime;
            var signInteractionDto = datalist[i].signInteractionDto;
            if (signInteractionDto != null) {
              var type1 = datalist[i].signInteractionDto.type;
              if (type1 == 4) {
                var txt = 0;
              }
              if (type1 == 3) {
                var txt = 1;
              }
              if (type1 == 6) {
                var txt = 2;
              }
              if (type1 == 5) {
                var txt = 3;
              }
              if (type1 == 1) {
                var txt = 4;
              }
              if (type1 == 2) {
                var txt = 5;
              }
              var cont = datalist[i].signInteractionDto.content;
              var gift = datalist[i].signInteractionDto.gift;
            }

            var oDate = new Date().getTime();
            var nTime = Math.abs(oDate - signinTime);
            var day1 = Math.floor(nTime / 86400000);
            var hour = Math.floor(nTime % 86400000 / 3600000);
            var minute = Math.floor(nTime % 86400000 % 3600000 / 60000);
            var day;
            if (hour >= 1 && hour < 24) {
              var day = hour + '小时'
            }
            if (day1 <= 0 && hour < 1 && minute >= 1) {
              var day = minute + '分钟'
            }
            if (minute < 1 && day1 < 1 && hour < 1) {
              var day = '刚刚'
            }
            if (day1 > 0) {
              var day = day1 + '天'
            }

            let obj = {}
            obj.height = 0,
              obj.pic = p || null,
              obj.name = name,
              obj.age = age,
              obj.day = day,
              obj.uid1 = uid1,
              obj.gender = gender,
              obj.exprise = exprise,
              obj.mid = mid,
              obj.gift = gift,
              obj.txt = txt,
              obj.height = 180,
              obj.content = cont,
              obj.merchantName = merchantName,
              obj.signInteractionDto = signInteractionDto
            personArr.push(obj)
            //personArr1.push(obj)
          }

          // if (personArr != null) {
          //   //that.data.totallist.concat(personArr);

          //   var oldlist = that.data.totallist;
          //   for (var i = 0; i < personArr.length; i++) {
          //     oldlist.push(personArr[i])
          //   }
          // }
  
          
          let img1 = {}
          let img2 = {}
          //let baseId = "img-" + (+new Date());
          let col1 = that.data.col1;
          let col2 = that.data.col2;
          let height = 0;
          for (let i = 0; i < personArr.length; i++) {
             
                if (i % 2 == 0) {

                  img1 = personArr[i]
                  col1H += 180
                  col1.push(img1)
                  //console.log(imageObj1)
                } else {

                  img2 = personArr[i]
                  col2H += 180
                  // img2.pop()
                  col2.push(img2)

                }
              
      
          }
         
        
          try {
            wx.setStorageSync('col1', col1);
            wx.setStorageSync('col2', col2);
          } catch (e) {
          }
         
          that.setData({
            personArr: personArr,
            col1:col1,
            col2:col2
          })

        //  try {
        //   wx.setStorageSync('judata', judata);
        //   wx.setStorageSync('datalist', datalist);
        // } catch (e) {
        // }

        }
      }

    },
    fail: function (res) {
      console.log(res)
      var errMsg = res.errMsg
      if (errMsg) {
        wx.showToast({
          title: '网络请求超时，请稍后重试',
          duration: 1000
        })
      }

    }
  })
}


Page({
  data:{
    src: [htp + 'pinzuo_bg_6_o.png', htp + 'pinzuo_bg_4_y.png', htp + 'pinzuo_bg_3_r.png', htp + 'pinzuo_bg_2_p.png', htp + 'pinzuo_bg_1_g.png', htp + 'pinzuo_bg_5_b.png'],
    colors: ['#f8a52c', '#f6e33e', '#ef4444', '#8c32d6', '#23c114', '#08cee1'],
    icon: ['pinzuo_6_pgz_color@2x.png', 'pinzuo_4_llt_color@2x.png', 'pinzuo_3_wyx_color@2x.png', 'pinzuo_2_qhd_color@2x.png', 'pinzuo_1_bgm_color@2x.png', 'pinzuo_5_bsh_color@2x.png'],
    icon2: ['buyuadrink_white@2x.png', 'cocktail_white@2x.png', 'beerbrew_white@2x.png', 'wine_white@2x.png', 'whiskey_white@2x.png', 'importbeer_white@2x.png', 'champagne_white@2x.png', 'brandy_white@2x.png', 'saki_white@2x.png'],
    tent: ['拼个座', '聊撩天', '玩游戏', '求回答', '帮个忙', '憋说话'],
    imagewidth: 0,//缩放后的宽  
    imageheight: 0,//缩放后的高  
    height2:0,
    indicatorDots: false,
    autoplay: false,
    circular: true,
    hiddenLoading: true,
    interval: 3000,
    duration: 500,
    toView: 'red',
    scrollLeft: 0,
    show: false,
    selectindex: 0,
    listpn: 0,
    kaiguan:false,
    scroll:true,
    msgArr:[],
    scrollH: 0,
    imgWidth: 0,
    loadingCount: 0,
    col1: [],
    col2: [],
    fabuH:0,
    hasRefesh: false
  },

  // getRoomPage: function () {
  //   return this.getPage("pages/chat/chat")//聊天界面
  // },
  // getPage: function (pageName) {
  //   var pages = getCurrentPages()
  //   return pages.find(function (page) {
  //     return page.__route__ == pageName
  //   })
  // }, 
 
  
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  swiperChange: function (event) {
    //console.log(this.data)
    var dots = this.data.dotsclass;
    for (var i = 0; i < dots.length; i++) {
      dots[i] = "";
    }
    dots[event.detail.current] = 'on';
    this.setData({
      dotsclass: dots
    });
  },

  showview: function (event) {
    var that = this;
    that.setData({
      show: true,
      selectindex: event.target.dataset.index
    })

    // console.log(that.data.show);
    //console.log(event.target.dataset.index);
  },
  hideview: function () {
    var that = this;
    that.setData({
      show: false
    })

    // console.log(that.data.show);
  },

  //提示开发中
  develop: function () {
    wx.showModal({
      title: '提示',
      content: '功能正在开发中，敬请期待',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {

        }
      }
    })
  },

   

  orderSign: function (e) {
    var fId = e.detail.formId;
    var fObj = e.detail.value;
    wx.setStorage({
      key: "fId",
      data: e.detail.formId
    })

  },


  onShow:function(){
      var that = this;
      var personArr = wx.getStorageSync('personArr') || [];   
      var uid = wx.getStorageSync('uid');
      // var mid = wx.getStorageSync('mid');
      city = wx.getStorageSync('city')
      wx.getNetworkType({
        success: function (res) {
          // 返回网络类型, 有效值：
          // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
          console.log(res)
          var networkType = res.networkType
          if (networkType == 'none') {
            wx.showToast({
              title: '无网络，请确认连接后重试',
              duration: 1000
            })
          }
        }
      })

     

      wx.getSystemInfo({
        success: (res) => {
          let ww = res.windowWidth;
          let wh = res.windowHeight;
          let imgWidth = ww * 0.48;
          let scrollH = wh;

          that.setData({
            scrollH: scrollH,
            imgWidth: imgWidth,
            w: ww,
            wh: wh
          });
         
        }
      })
      // that.setData({
      //   hiddenLoading: false
      // })
     
    
      getList(that)

      for (var i = 0; i < personArr.length; i++) {
        if (personArr[i].isShow) {
          that.setData({
            showbox: true
          })
        } else {
          that.setData({
            showbox: false
          })
        }
      }

      //var falg = false
      wx.getStorage({
        key: 'chatMsg1',
        success: function (res) {
          console.log(res.data)
          
          if (res.data.data) {
            that.setData({
              showbox: true
            })        

          }
        }
      })
     // falg = true
     // console.log(chatMsg1)
  
    

       // 优惠套餐
      // wx.request({
      //   url: https + 'v2/mpackage/open/list/123',
      //   dataType: "json",
      //   success: function (res) {
      //     var listdata = res.data;
      //     if (listdata.success) {
      //       var list = listdata.data.list;
      //       console.log(list)

      //       var cunlist = [];//创建一个新数组
      //       for (var key in list) {
      //         //console.log(list[key])
      //         //var name = list[key].merchantName;//酒吧名
      //         var photos = list[key].photos;//图片
      //         var photo = photos.split(';');
      //         var price = list[key].price;//现价
      //         var oldprice = list[key].oldPrice.toFixed(1);//原价
      //         var title = list[key].title;//标题
      //         var person = list[key].personNum;//人数
      //         var pid = list[key].pid;

      //         var obj = {};//创建新对象
      //         // obj.tags = tags;
      //         // obj.name = name;
      //         obj.price = price;
      //         obj.oldprice = oldprice;
      //         obj.title = title;
      //         obj.photos = photos;
      //         obj.photo = photo;
      //         obj.person = person;
      //         obj.pid = pid;
      //         cunlist.push(obj);

      //       };
      //       console.log(cunlist)

      //       for (var i = 0; i < cunlist.length; i++) {
      //         var photo = cunlist[i].photo;
      //         var dots = [];//轮播指示器
      //         for (var j = 0; j < photo.length; j++) {
      //           dots.push("");
      //         }
      //         dots[0] = 'on';
      //       }

      //     }

      //     that.setData({
      //       cunlist: cunlist,
      //       dotsclass: dots,
      //     })
      //   }

      // })

  
     
  },
  // globalData: {
  //   userInfo: null,
  //   chatMsg: []

  // },



  loadImages: function () {
    var that = this
    //var mid = wx.getStorageSync('mid');
    page += 1;
    console.log('page', page)
    personList(that, mid)
    
  },

  onReady:function(){
    this.loadImages();
  },
  //返回上一页面
  onUnload:function(){
    var that = this
    page = -1
    that.setData({
      showPerson:false
    })
  },
  onHide:function(){
    var that = this
    that.setData({
      showPerson: false
    })
  },


  onLoad: function (options) {
    var that = this;
     pages = getCurrentPages()
    console.log(pages)
     mid = options.mid;
     //mid = 200
    //var midName = options.midName;
    var uid = wx.getStorageSync('uid');
    var access_token = wx.getStorageSync('inToken');
    var myName = wx.getStorageSync('myUsername')
    var sex = wx.getStorageSync('sex')
    var thumb = wx.getStorageSync('thumb')
    //var fromId = options.from
    try {
      wx.setStorageSync('mid', mid);
    } catch (e) {
    }
   that.setData({
     mid:mid
   })
    
    //活动
    wx.request({
      url: https + 'v1/merchant/open/detail/'+mid + '?uid=' + uid,
      dataType: "json",
      success: function (res) {
        console.log(res)
        var respData = res.data;
        if (respData.success) {
          var business = respData.data
          tp = business.type
          console.log(business)
          var newpoint = business.sellingPoint
          try {
            wx.setStorageSync('midName', business.name);
          } catch (e) {
          }
          wx.setNavigationBarTitle({//设置标题
            title: business.name
          });
        
        }
        that.setData({
          business: business,
          newpoint: newpoint,
        })
        console.log(tp)
        // if(tp==3&&!kaiguan){
        //   // var fromId = wx.getStorageSync('fromId');
        //   // var mid = wx.getStorageSync('mid');
        //   //var mid = 200 
        //   //if (fromId == 0) {
        //   kaiguan = wx.getStorageSync('kaiguan') || null;  
        //     wx.request({
        //       url: https + 'v1/signin/miniapp?uid=' + uid + '&access_token=' + access_token,
        //       method: 'POST',
        //       header: {
        //         'content-type': 'application/json',
        //       },
        //       data: {
        //         // 'userLat': '30.632938',
        //         // 'userLng': '104.054685',
        //         'mid': mid,
        //         'merchantName': '',
        //         'userLat': 0,
        //         'userLng': 0,
        //         'uid': uid,
        //         'userName': myName,
        //         'access_token': access_token

        //       },
        //       success: function (res) {
        //         console.log(res)
        //         var signData = res.data.data;
        //         if (res.data.success) {
        //           wx.setStorage({
        //             key: "signData2",
        //             data: signData
        //           })

        //           that.setData({
        //             showView: true,
        //             scroll: false
        //           })
        //           kaiguan = true
        //           try {
        //             wx.setStorageSync('kaiguan', kaiguan)
        //           } catch (e) {
        //           }
        //         }



        //       },
        //       fail: function () {
        //         try {
        //           wx.removeStorageSync('fromId')
        //           wx.removeStorageSync('mid')
        //         } catch (e) {
        //         }
        //       }
        //     })

        //   //}

        // }

      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    });


    try {
      wx.setStorageSync('mid', mid);
      //wx.setStorageSync('fromId', fromId);
    } catch (e) {
    }


  

  
    // wx.getLocation({
    //   type: 'wgs84',
    //   success: function (res) {
    //     var latitude = res.latitude
    //     var longitude = res.longitude
    //     var speed = res.speed
    //     var accuracy = res.accuracy
    //   }
    // })


     //签到弹出框人数显示
      wx.request({
        url: https + 'v1/signin/open/merchants/'+mid,
        success: function (res) {
          console.log(res.data.data)
          var sigData = res.data.data
          var users = sigData.users
          var user0 = users[0]
          var user1 = users.slice(1)

          for (var i = 0; i < user1.length; i++) {
            if (user1.length < 4) {
              users = user1.slice(0);
            } else {
              users = user1.slice(0, 3);
            }
          }
          console.log(users)
          that.setData({
            sigData: sigData,
            users: users,
            user0: user0
          })

        }
      })

   
    var lat1 = wx.getStorageSync('lat1');
    var lng1 = wx.getStorageSync('lng1');
    console.log('lat', lat1)
    //签到(搜索)
   
    //if(fromId==1){
     
      wx.request({
        url: https + 'v1/signin/auto?city='+city+'&uid=' + uid + '&access_token=' + access_token,
        method: 'POST',
        header: {
          'content-type': 'application/json',
        },
        data: {
          'city': city,
          // 'userLat': '30.632938',
          // 'userLng': '104.054685',
          'userLat': lat1,
          'userLng': lng1,
          'uid': uid,
          'userName': myName,
          'access_token': access_token

        },
        success: function (res) {
          console.log(res)
          var signData = res.data.data;
          kaiguan = wx.getStorageSync('kaiguan') || null;
          if (!res.data.success) {
            console.log('未签到成功')
          } else if (res.data.success && signData != null && signData.mid == mid && !kaiguan) {
            that.setData({
              showView: true,
              scroll: false
            })
            kaiguan = true
            try {
              wx.setStorageSync('kaiguan', kaiguan)
            } catch (e) {
            }

          }
         
        }
       
      })
      
      //签到(扫码)
   // }else{
      // wx.getStorage({
      //   key: 'signData2',
      //   success: function (res) {
      //     console.log(res.data)
      //     var col1 = wx.getStorageSync('col1');
      //     var col2 = wx.getStorageSync('col2');
      //     for(var i=0;i<col1.length;i++){
      //       for (var j = 0; j < col2.length; j++){
      //         if (col1[i].uid1 == uid && res.data.signin && res.data.update || col2[j].uid1 == uid && res.data.signin && res.data.update) {
      //           that.setData({
      //             showPerson: false
      //           })
      //         } else {
      //           that.setData({
      //             thumb: thumb,
      //             myName: myName,
      //             sex: sex,
      //             showPerson: true
      //           })
      //         }
      //         break
      //       }
      //       break
      //     }
         
      //     if (res.data.signin && res.data.update){
      //       that.setData({
      //         showView: true,
      //         scroll: false
      //       })
      //     }
      //   }
      // })
     
    //}  
     
    

  } ,

  opaBox:function(){
      var that = this;
      that.setData({
        showView:false,
        scroll:true
      })
  },
  //进入商家公告
  into_merlist:function(){
    wx.navigateTo({
      url: '../merchantlist/merchantlist?mid=' + mid,
      success: function (res) {

      },
      fail: function (res) { },
      complete: function (res) { },
    })

  },

  //进入活动页
  into_actives:function(){
      wx.navigateTo({
        url: '../actives/actives?mid=' + mid,
        success: function (res) {

        },
        fail: function (res) { },
        complete: function (res) { },
      })

  },
  
 //进入商家动态
  into_mertrend:function() {
    wx.navigateTo({
      url: '../mertrend/mertrend?mid=' + mid,
      success: function (res) {

      },
      fail: function (res) { },
      complete: function (res) { },
    })

  },
  //进入发布页
  openInter: function () {
    var dataArr = wx.getStorageSync('dataArr');
    var resData = wx.getStorageSync('resData');
    var uid = wx.getStorageSync('uid');
   // var mid = wx.getStorageSync('mid');
    // var datalist = wx.getStorageSync('datalist');
    // var judata = wx.getStorageSync('judata');
    // console.log(judata)
   wx.request({
     url: https + 'v1/signin/open/merchants/morespace/' + mid,
     data: {
       pn: 0,
       ps: 100
     },
     //dataType: "application/json",
     success: function (res) {
       var falg;
        if(res.data.data!=null){
          var datalist2 = res.data.data.sininMoreSpaces;
          for (var i = 0; i < datalist2.length; i++) {

            if (uid != datalist2[i].uid) {

              falg = false;

            } else {
              falg = true;

              break;
            }

          }
        }else{
          wx.showModal({
            title: '提示',
            content: '未签到不能发拼座，快点击他人头像聊天吧',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {

              }
            }
          })
        }

        console.log(falg)
        if (falg) {
          var isfb;

          if (resData != null) {
            for (var k in dataArr) {

              if (dataArr[k].uid2 == uid && dataArr[k].exprise1 == 2) {
                isfb = false;

                break;

              } else if (dataArr[k].uid2 == uid && dataArr[k].exprise1 != 2) {

                isfb = true;
                break;

              } else {
                isfb = true;
              }

            }
          } else {
            isfb = true;
          }

          console.log(isfb)
          if (isfb) {
            wx.navigateTo({
              url: '../interaction/interaction?mid=' + mid,
              success: function (res) {

              },
              fail: function (res) { },
              complete: function (res) { },
            })

          } else {
            // wx.showModal({
            //   title: '提示',
            //   content: '你已发过拼座，请结束后再试',
            //   showCancel: false,
            //   success: function (res) {
            //     if (res.confirm) {
            //       return false;
            //     }
            //   }
            // })
            for (var n in dataArr) {
              if (dataArr[n].uid2 == uid && dataArr[n].exprise1 == 2) {
                  var thumb = dataArr[n].userThumb
                  var cont = dataArr[n].content
                  var leg = dataArr[n].gift-1
                  var merchantName = dataArr[n].merchantName
                  var timestamp = dataArr[n].timestamp
                  var nickName = dataArr[n].nickName
                  var sid = dataArr[n].sid
                  var uid2 = dataArr[n].uid2
                  var txt = dataArr[n].txt
                  var gender = dataArr[n].gender
              } 
              

            } 
            wx.navigateTo({
              url: '../posting_del/posting_del?thumb=' + thumb + '&txt=' + txt + '&cont=' + cont + '&leg=' + leg + '&merchantName=' + merchantName + '&timestamp=' + timestamp + '&nickName=' + nickName + '&sid=' + sid + '&uid2=' + uid2 +'&gender='+gender,
            })
          }
        } else {
          wx.showModal({
            title: '提示',
            content: '未签到不能发拼座，快点击他人头像聊天吧',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {

              }
            }
          })
        }
     } 
   })

    // var falg;
    // if(judata!=null){
    //   for (var i = 0; i < datalist.length; i++) {

    //     if (uid != datalist[i].uid) {

    //       falg = false;

    //     } else {
    //       falg = true;

    //       break;
    //     }

    //   }
    // }else{
    //   wx.showModal({
    //     title: '提示',
    //     content: '未签到不能发拼座，快点击他人头像聊天吧',
    //     showCancel: false,
    //     success: function (res) {
    //       if (res.confirm) {

    //       }
    //     }
    //   })
    // }
   
    
   that.setData({
     isOpacity: false
   })


  },
  //进入聊天
  into_chat: function (e) {
    var that =this;
    var access_token = wx.getStorageSync('inToken');
    var uid = wx.getStorageSync('uid');
    var col1 = wx.getStorageSync('col1');
    var idx = e.currentTarget.dataset.idx;
    console.log(e)
   
    var myName = wx.getStorageSync('myUsername')

    var nameList = {}
    nameList.myName = myName,
    nameList.your = col1[idx].uid1,
    nameList.yourName = col1[idx].name,
    nameList.userAvatar = col1[idx].pic  
   
    if (uid != col1[idx].uid1) {
      // that.setData({
      //   showbox: false,
      //   isinto: true
      // })
      wx.navigateTo({
        url: '../chat/chat?username=' + JSON.stringify(nameList)
      })


      wx.setTopBarText({
        text: 'More摩儿-在酒吧发现有趣朋友'
      })
      
    } 

  },

  into_chat2: function (e) {
    var that = this;
    var access_token = wx.getStorageSync('inToken');
    var uid = wx.getStorageSync('uid');
    var col2 = wx.getStorageSync('col2');
    var idy = e.currentTarget.dataset.idy;
    console.log(e)

    var myName = wx.getStorageSync('myUsername')
  
      var nameList = {}
      nameList.myName = myName,
      nameList.your = col2[idy].uid1,
      nameList.yourName = col2[idy].name,
      nameList.userAvatar = col2[idy].pic

    if(uid!=col2[idy].uid1){
      // that.setData({
      //   showbox: false,
      //   isinto: true
      // })
      wx.navigateTo({
        url: '../chat/chat?username=' + JSON.stringify(nameList)
      })   
      wx.setTopBarText({
        text: 'More摩儿-在酒吧发现有趣朋友'
      })
    } 
  
   
  },

  //遮罩层
  openOpcaty: function () {
    var that = this;
    that.setData({
      isOpacity: true
    })
  },
  colse: function () {
    var that = this;
    that.setData({
      isOpacity: false
    })
  },

  //进入发布动态
  pubstate: function () {
    var that = this;
    wx.navigateTo({
      url: '../dynamics/dynamics'
    })
    that.setData({
      isOpacity: false
    })
  },
  //返回上页
  backTag:function(){
    // if (pages[1].route == 'pages/index/index') {
    //   wx.navigateBack({
    //     delta: 1
    //   })
    // } else if (pages[0].route == 'pages/index/index'){
    //   wx.navigateTo({
    //     url: '../home/home'
    //   })
    // } 
    wx.redirectTo({
      url: '../home/home'
    })
   
  },
  //跳转另个小程序
  tiaozhuan: function () {
    wx.navigateToMiniProgram({
      appId: 'wx3abd6a1e615ce065',
      path: '',
      extraData: {
        foo: 'bar'
      },
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },

  into_chatlist:function(){
    var that = this;
  
    wx.navigateTo({
      url: '../chatlist/chatlist'
    })
    //isinto:true
    try {
      wx.removeStorageSync('chatMsg1')
    } catch (e) {
    }
   
    wx.setTopBarText({
      text: 'More摩儿-在酒吧发现有趣朋友'
    })

    // wx.setTopBarText({
    //   text: 'More精选酒吧'
    // })
  },

  isHide:function(e){
      this.setData({
        showView:false
      })
  },  

 // 页面上拉触底事件的处理函数
  // onReachBottom: function () {
  //   var that = this;
  //   var mid = wx.getStorageSync('mid');
  //   if (that.data.images != null && that.data.images.length != 0) {
  //     that.setData({
  //       hiddenLoading: false
  //     })
  //     page += 1;
  //     personList(that, mid)
  //     // if (that.data.images.length - (page - 1) * 10 < 10) {
  //     //   that.setData({
  //     //     hiddenLoading: true
  //     //   })
  //     // }
  //   } else if (that.data.images.length - (page - 1) * 10==0){
  //     return false
  //     wx.showToast({
  //       title: '已加载完成',
  //       duration: 1000
  //     })

  //   }
  // },

  imageLoad: function (e) {
    var imageSize = imageUtil.imageUtil(e)
    this.setData({
      imagewidth: imageSize.imageWidth,
      imageheight: imageSize.imageHeight,
      height2: imageSize.imageHeight2
    })
   
  },
  openMap: function (event) {
    console.log(event.target.dataset)
    wx.openLocation({
      latitude: event.target.dataset.lat, // 纬度，范围为-90~90，负数表示南纬
      longitude: event.target.dataset.lng, // 经度，范围为-180~180，负数表示西经
      scale: 28, // 缩放比例          
    })
  },   

  //点击banner
  

  onShareAppMessage: function () {
    var pages = getCurrentPages()
    //var mid = wx.getStorageSync('mid');
    var midName = wx.getStorageSync('midName');
    // var path;
    // console.log(pages)
    // if (pages[0].route == 'pages/index/index') {
    //   path: '/pages/index/index?mid=' + mid + '&from=0'
    // } else if (pages[1].route == 'pages/index/index') {
    //   path: '/pages/index/index?mid=' + mid + '&from=1'
    // }
    // 用户点击右上角分享
    return {
      title: '我在' + midName + '等你来', // 分享标题
      desc: '我在'+midName+'等你来', // 分享描述
     
      path: '/pages/index/index?mid=' + mid 
    }
  }
})
